package fr.inserm.u915.organifooyi.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fr.inserm.u915.organifooyi.controlers.MainHandler;

public class MainControler extends HttpServlet
	{
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest httpreq, HttpServletResponse httpresp)
			throws ServletException, IOException
		{
		RequestHandler handler=null;
		
		try
			{
			handler=new MainHandler();
			if(handler!=null)
				{
				HttpServletRequestWrapper req=new HttpServletRequestWrapper(httpreq);
				HttpServletResponseWrapper resp=new HttpServletResponseWrapper(httpresp);
				handler.setRequest(req);
				handler.setResponse(resp);
				handler.service();
				}
			}
		catch(IOException err)
			{
			throw err;
			}
		catch(ServletException err)
			{
			throw err;
			}
		catch(Throwable err)
			{
			throw new ServletException(err);
			}
		finally
			{
			if(handler!=null) handler.close();
			}
		
		
		}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
		}
	
	}
